package com.haojin.java;

/**
 *
 * 例子：创建三个买票窗口买票，总票数为100张.使用实现Runnable接口的方式来做
 *
 * 存在线程的安全问题，待解决
 *
 * @author .29.
 * @create 2022-03-30 15:28
 */

class Window1 implements Runnable{

    private int ticket = 100;
    @Override
    public void run() {
        while(true){
            if(ticket > 0){
                System.out.println(Thread.currentThread().getName()+"卖票，票号为："+ticket);
                ticket--;
            }else break;
        }
    }
}

public abstract class WindowTest1 {
    public static void main(String[] args) {
        Window1 p = new Window1();
        Thread T1 = new Thread(p);
        Thread T2 = new Thread(p);
        Thread T3 = new Thread(p);

        T1.setName("窗口1");
        T2.setName("窗口2");
        T3.setName("窗口3");

        T1.start();
        T2.start();
        T3.start();

    }




}
